﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace week8_3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string fontName = textBox2.Text;
            float fontsize = Convert.ToSingle(textBox1.Text);
           // label1.Font = new Font(textBox2.Text,fontsize);//此遇见不会保留字
            label2.Font = new Font(textBox2.Text,fontsize,label2.Font.Style);
        }
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            /*
             * ===================方法- BEGIN====================
             *
            FontStyle fs = (FontStyle.Bold | FontStyle.Italic | FontStyle.Underline);
                if(!checkBox1.Checked)
                    fs -=FontStyle.Bold;//去除加粗效果
                if(!checkBox2.Checked)
                    fs-=FontStyle.Italic;//去除斜体效果
                if(!checkBox3.Checked)
                    fs-=FontStyle.Underline;//去除下划线效果
            label2.Font = new Font(label2.Font,fs);
             * 
             * ====================方法一 END=================================
             */

            /*
             * ========================方法二===========================
             */
            if (checkBox1.Checked)
                label2.Font = new Font(label2.Font, label2.Font.Style | FontStyle.Bold);//加粗效果
            else
                label2.Font = new Font(label2.Font, label2.Font.Style & ~FontStyle.Bold);//取消加粗

            if (checkBox2.Checked)
                label2.Font = new Font(label2.Font, label2.Font.Style | FontStyle.Italic);//倾斜效果
            else
                label2.Font = new Font(label2.Font, label2.Font.Style & ~FontStyle.Italic);//取消倾斜效果

            if (checkBox3.Checked)
                label2.Font = new Font(label2.Font, label2.Font.Style | FontStyle.Underline);//下划线效果
            else
                label2.Font = new Font(label2.Font, label2.Font.Style & ~FontStyle.Underline);//取消下划线效果
             

        }
    }
}
